package com.example.english.controller;

import com.example.english.pojo.PageBean;
import com.example.english.pojo.Result;
import com.example.english.pojo.Student;
import com.example.english.pojo.Teacher;
import com.example.english.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;


    /**
     *   查询所有学生四级成绩
     */
    @GetMapping("/student")
    public Result list(@RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("分页查询，参数:{},{}",pageNum,pageSize);

        PageBean pageBean = studentService.list(pageNum,pageSize);
        return Result.success(pageBean);
    }


    /**
     *   添加学生
     */
    @PostMapping("/student/add")
    public Result Add(@RequestBody Student student){
        log.info("添加学生:{}",student);

        studentService.add(student);
        return Result.success();
    }

    /**
     *   删除学生
     */
    @DeleteMapping("/student/delete/{id}")
    public Result Delete(@PathVariable Long id){
        log.info("根据id删除学生:{}",id);
        studentService.delete(id);
        return Result.success();
    }


    /**
     *   修改学生
     */
    @PutMapping("/student/update")
    public Result Update(@RequestBody Student student){
        log.info("修改学生:{}",student);
        studentService.update(student);
        return Result.success();
    }

    /**
     *   序列号查找学生
     */
    @GetMapping("/selectStudentBySerialNumber")
    public Result BySerialNumber(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 @RequestParam Long inputKeyword){
        log.info("根据序列号返回记录:{}",inputKeyword);
        PageBean pageBean = studentService.BySerialNumber(pageNum,pageSize,inputKeyword);
        return Result.success(pageBean);
    }


    /**
     *   学号查找学生
     */
    @GetMapping("/selectStudentByStudentId")
    public Result ByStudentId(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 @RequestParam Integer inputKeyword){
        log.info("根据学号返回记录:{}",inputKeyword);
        PageBean pageBean = studentService.ByStudentId(pageNum,pageSize,inputKeyword);
        return Result.success(pageBean);
    }

    /**
     *   姓名查找学生
     */
    @GetMapping("/selectStudentByName")
    public Result ByName(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 @RequestParam String inputKeyword){
        log.info("根据姓名返回记录:{}",inputKeyword);
        PageBean pageBean = studentService.ByName(pageNum,pageSize,inputKeyword);
        return Result.success(pageBean);
    }

    /**
     *   性别查找学生
     */
    @GetMapping("/selectStudentByGender")
    public Result ByGender(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 @RequestParam String inputKeyword){
        log.info("根据性别返回记录:{}",inputKeyword);
        PageBean pageBean = studentService.ByGender(pageNum,pageSize,inputKeyword);
        return Result.success(pageBean);
    }


    /**
     *   年龄查找学生
     */
    @GetMapping("/selectStudentByAge")
    public Result ByAge(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 @RequestParam Integer inputKeyword){
        log.info("根据年龄返回记录:{}",inputKeyword);
        PageBean pageBean = studentService.ByAge(pageNum,pageSize,inputKeyword);
        return Result.success(pageBean);
    }


    /**
     *   联系方式查找学生
     */
    @GetMapping("/selectStudentByPhoneNumber")
    public Result ByPhoneNumber(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 @RequestParam Long inputKeyword){
        log.info("根据联系方式返回记录:{}",inputKeyword);
        PageBean pageBean = studentService.ByPhoneNumber(pageNum,pageSize,inputKeyword);
        return Result.success(pageBean);
    }


    /**
     *   成绩查找学生
     */
    @GetMapping("/selectStudentByGrades")
    public Result ByGrades(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 @RequestParam Integer inputKeyword){
        log.info("根据成绩返回记录:{}",inputKeyword);
        PageBean pageBean = studentService.ByGrades(pageNum,pageSize,inputKeyword);
        return Result.success(pageBean);
    }
}
